
package net.mcreator.makecustomitem;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import net.mcreator.makecustomitem.AttrHelper;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;

public class AttrCommand extends CommandBase {

	@Override
	public String getName() {
		return "attr";
	}

	@Override
	public String getUsage(ICommandSender sender) {
		return "";
	}

	@Override
	public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
		if (args.length != 3)
			throw new WrongUsageException("");
		else {
			EntityLivingBase living;
			Float count;
			AttrHelper.OPERATIONS.get(args[0]).accept(living = getPlayer(server, sender, args[1]),
					count=Float.valueOf(args[2]));
//			living.sendMessage(new TextComponentTranslation("commands.attr.des."+args[0],living.getDisplayName(),count));
		}
	}
	
	@Override
	public int getRequiredPermissionLevel() {
		return 2;
	}
	
	@Override
    public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
    {
		List<String> result=new ArrayList<>();
		if(args.length==1) {
			result.addAll(CommandBase.getListOfStringsMatchingLastWord(args,AttrHelper.OPERATIONS.keySet())); 
		}
		else if(args.length==2) {
			//result.addAll(CommandBase.getListOfStringsMatchingLastWord(args,server.getOnlinePlayerNames()));
			result.addAll(getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()));
		}
        return result;
    }
}
